package com.digitaleye.dpslite;



import org.json.JSONException;
import org.json.JSONObject;

import android.database.Cursor;

public class Account {
	
	public double amount = 0;
	
	public String name;
	
	public int id;
	
	String firstName;
	String lastName;
	String birthdate;

	
	
	Account(String name, int amount){
		
		this.name = name;

		this.amount = amount;
	}
	
	Account(JSONObject json){
		
		try{
			this.name = (String) json.getString("name");
			this.id = json.getInt("_id");

			
			this.amount = json.getDouble("amount");
			
			this.firstName = json.getString("firstName");
			this.lastName = json.getString("lastName");
			this.birthdate = json.getString("birthdate");


		}
		catch(JSONException e){
			e.printStackTrace();
		}
		
		
		
		
		
	}
	
	Account(Cursor accountCursor){
		
		
		
		if(accountCursor.moveToFirst()){
			
			id = accountCursor.getInt(accountCursor.getColumnIndex("_id"));
			name = accountCursor.getString(accountCursor.getColumnIndex(AccountDBHelper.COLUMN_ACCOUNT_NAME));
			
			amount = accountCursor.getInt(accountCursor.getColumnIndex(AccountDBHelper.COLUMN_ACCOUNT_AMOUNT));
			
			firstName = accountCursor.getString(accountCursor.getColumnIndex(AccountDBHelper.COLUMN_ACCOUNT_FIRSTNAME));
			firstName = accountCursor.getString(accountCursor.getColumnIndex(AccountDBHelper.COLUMN_ACCOUNT_LASTNAME));
			birthdate = accountCursor.getString(accountCursor.getColumnIndex(AccountDBHelper.COLUMN_ACCOUNT_BIRTHDATE));

		}
		else{
			try {
				throw new Exception("ACCOUNT CURSOR IS EMPTY!");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		//accountCursor.close();

		
	}
	
	Account(){
		firstName = "";
		lastName = "";
		birthdate ="";

		
	}
	
	

}
